home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_064 / examples / uncycle.c < prev   
C/C++ Source or Header  |  1992-05-06  |  4KB  |  168 lines

  1. /*
  2.  * Uncycle.c - C. Scheppner  01/87
  3.  *
  4.  *   Disables cycling chunks (CRNGs) of DPaint pic by killing active
  5.  *      bit and setting RNG_NORATE (36) for cycle rate
  6.  *   This can also be accomplished with DPaint, by reloading the
  7.  *      pic, setting the cycle speed for each to the lowest position,
  8.  *      and re-saving the pic
  9.  *   (Default DPaint CRNG chunks are Active with rate 0xAAA)
  10.  *
  11.  *   LINKAGE INFO:
  12.  *     Compile with -v flag on LC2
  13.  *     Link with AStartup.obj ... LIBRARY Amiga.lib, LC.lib
  14.  */
  15.  
  16. #include <exec/types.h>
  17. #include <libraries/dos.h>
  18. #include <libraries/dosextens.h>
  19. #include <workbench/startup.h>
  20.  
  21. extern struct WBStartup *WBenchMsg;
  22.  
  23. struct FileLock *startLock, *newLock;
  24. BOOL fromWB;
  25.  
  26. /* For wbStdio rtns */
  27. extern LONG stdin, stdout, stderr;  /* in Astartup.obj */
  28. char conSpec[] = "CON:0/40/640/140/";
  29. BOOL wbHasStdio = NULL;
  30.  
  31. #define BUFSIZ 400
  32.  
  33. main(argc, argv)
  34. int argc;
  35. char **argv;
  36.    {
  37.    LONG            file, rLen;
  38.    struct WBArg    *arg;  
  39.    char            *filename;
  40.    char  buf[BUFSIZ], *bp;
  41.    int k;
  42.  
  43.    fromWB = (argc==0) ? TRUE : FALSE;
  44.  
  45.    if(argc>1)                 /* Passed filename via command line  */
  46.       {
  47.       filename = argv[1];
  48.       }
  49.    else if ((argc==0)&&(WBenchMsg->sm_NumArgs > 1))
  50.       {                        /* Passed filename via  WorkBench */
  51.       arg = WBenchMsg->sm_ArgList;
  52.       arg++;
  53.       filename   = (char *)arg->wa_Name;
  54.       newLock    = (struct FileLock *)arg->wa_Lock;
  55.       startLock  = (struct FileLock *)CurrentDir(newLock);
  56.       }
  57.    else if (argc==1)           /* From CLI but no filename */
  58.       cleanexit("Usage: requires ILBM filename");
  59.    else                        /* From WB but no filename */
  60.       cleanexit(
  61.          "Usage:\nClick ONCE on this Icon\nSHIFT and DoubleClick on Pic");
  62.  
  63.  
  64.    if(!(file = Open(filename, MODE_OLDFILE)))
  65.       cleanexit("Picture file not found");
  66.  
  67.    rLen = Read(file,buf,BUFSIZ);
  68.    for(k=0, bp=&buf[0]; k<BUFSIZ-12; k++,bp++)
  69.       {
  70.       if((bp[0]=='C')&&(bp[1]=='R')&&(bp[2]=='N')&&(bp[3]=='G'))
  71.          {
  72.          bp[10]  = 0x00; /* Rate RNG_NORATE (36) */
  73.          bp[11]  = 0x24;
  74.          bp[13] &= 0xFE; /* Clear active bit */
  75.          }
  76.       }
  77.    Seek(file,0,OFFSET_BEGINING);
  78.    Write(file,buf,rLen);
  79.    Close(file);
  80.    cleanup();
  81.    }
  82.  
  83.  
  84. cleanexit(s)
  85.    char  *s;
  86.    {
  87.    if (*s)
  88.       {
  89.       if ((fromWB)&&(! wbHasStdio))  wbHasStdio = openStdio(conSpec);
  90.  
  91.       if ((!fromWB)||(wbHasStdio))
  92.          {
  93.          Write(stdout,s,strlen(s));
  94.          Write(stdout,"\n",1);
  95.          }
  96.       if (wbHasStdio)
  97.          {
  98.          Write(stdout,"\nPRESS RETURN TO EXIT\n",22);
  99.          while (getchar() != '\n');
  100.          }
  101.       }
  102.    if (wbHasStdio) closeStdio();
  103.    cleanup();
  104.    exit();
  105.    }
  106.  
  107. cleanup()
  108.    {
  109.    if(newLock != startLock)  CurrentDir(startLock);
  110.    }
  111.  
  112. strlen(s)
  113. char *s;
  114.    {
  115.    int i = 0;
  116.    while(*s++) i++;
  117.    return(i);
  118.    }
  119.  
  120.  
  121.  
  122.  
  123. /* wbStdio.c --- Open an Amiga stdio window under workbench
  124.  *               For use with AStartup.obj
  125.  */
  126.  
  127. openStdio(conspec)
  128. char *conspec;
  129.    {
  130.    LONG wfile;
  131.    struct Process *proc;
  132.    struct FileHandle *handle;
  133.  
  134.    if (wbHasStdio)  return(1);
  135.  
  136.    if (!(wfile = Open(conspec,MODE_NEWFILE)))  return(0);
  137.    stdin  = wfile;
  138.    stdout = wfile;
  139.    stderr = wfile;
  140.    handle = (struct FileHandle *)(wfile << 2);
  141.    proc = (struct Process *)FindTask(NULL);
  142.  
  143.    proc->pr_ConsoleTask = (APTR)(handle->fh_Type);
  144.    proc->pr_CIS = (BPTR)stdin;
  145.    proc->pr_COS = (BPTR)stdout;
  146.    return(1);
  147.    }
  148.  
  149. closeStdio()
  150.    {
  151.    struct Process *proc;
  152.    struct FileHandle *handle;
  153.  
  154.    if (! wbHasStdio) return(0);
  155.  
  156.    if (stdin > 0)  Close(stdin);
  157.    stdin  = -1;
  158.    stdout = -1;
  159.    stderr = -1;
  160.    handle = (struct FileHandle *)(stdin << 2);
  161.    proc = (struct Process *)FindTask(NULL);
  162.    proc->pr_ConsoleTask = NULL;
  163.    proc->pr_CIS = NULL;
  164.    proc->pr_COS = NULL;
  165.    wbHasStdio = NULL;
  166.    }
  167.  
  168.